import { defHttp } from '/@/utils/http';
import { rsaEncryption } from '/@/utils/cipher';

export function getCodeImgApi() {
  return defHttp.get<any>({ url: '/api/auth/code' });
}

export function getUserInfoApi() {
  return defHttp.get<any>({ url: '/api/auth/info' });
}

/**
 * @description: user login api
 */
export function loginApi(params: any) {
  return defHttp.post<any>({ url: '/api/auth/login', params });
}

/**
 * @description: user logout
 */
export function logoutApi() {
  return defHttp.delete({ url: '/api/auth/logout' });
}

export function getUserLogsApi(params: any) {
  return defHttp.get<any>({ url: '/api/logs/user', params }, { joinParamsToUrl: true });
}

export function getUsersApi(params: any) {
  return defHttp.get<any>({ url: '/api/users', params }, { joinParamsToUrl: true });
}

export function addUserApi(params: any) {
  return defHttp.post<any>({ url: '/api/users', params });
}

export function editUserApi(params: any) {
  return defHttp.put<any>({ url: '/api/users', params });
}

export function delUserApi(ids: any) {
  return defHttp.delete<any>({ url: '/api/users', params: ids });
}

export function editUserCenterApi(params: any) {
  return defHttp.put<any>({ url: '/api/users/center', params });
}

export function updatePassApi(params: any) {
  const data = {
    oldPass: rsaEncryption.encryptByRSA(params.oldPass),
    newPass: rsaEncryption.encryptByRSA(params.newPass),
  };
  return defHttp.post<any>({ url: '/api/users/updatePass', data });
}
